package day04.dao;

import org.apache.commons.dbutils.QueryRunner;

import java.sql.Connection;
import java.sql.SQLException;

public class AccountDao {
    /**
     * 转账
     * @param conn
     * @param outName
     * @param meony
     * @throws SQLException
     */
    public void outMoney(Connection conn,String outName,int meony) throws SQLException{
        QueryRunner queryRunner = new QueryRunner();
        String sql = "update account set money = money-? where name = ?";
        queryRunner.update(conn,sql,meony,outName);
    }

    /**
     * 加钱
     * @param inName 收钱人姓名
     * @param money 转账金额
     */
    public void inMoney(Connection conn,String inName, int money) throws SQLException {
        QueryRunner qr = new QueryRunner();
        String sql = "update account set money = money + ? where name = ?";
        qr.update(conn, sql, money, inName);
    }
}
